<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Happy ERP</title>
    <%= stylesheet_link_tag "/javascripts/ext/resources/css/ext-all.css" %>
    <%= stylesheet_link_tag "/stylesheets/tasks.css" %>
    <%= stylesheet_link_tag "/stylesheets/images.css" %>
    <%= stylesheet_link_tag "/javascripts/ext/examples/ux/css/ColumnNodeUI.css" %>


    <%= javascript_include_tag "ext/adapter/ext/ext-base.js" %>
    <%= javascript_include_tag "ext/ext-all.js" %>
    <%= javascript_include_tag "ext/src/locale/ext-lang-zh_CN.js" %>
    <%= javascript_include_tag "ext/examples/ux/ColumnNodeUI.js" %>
    <%= javascript_include_tag "ext/examples/ux/TabCloseMenu.js" %>

    <script type="text/javascript">
      Ext.QuickTips.init();
      Ext.lib.Ajax.defaultPostHeader += ";charset=UTF-8";
      Ext.apply(Ext.form.VTypes, {
        daterange : function(val, field) {
          var date = field.parseDate(val);

          if(!date){
            return;
          }
          if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
            var start = Ext.getCmp(field.startDateField);
            start.setMaxValue(date);
            start.validate();
            this.dateRangeMax = date;
          }
          else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
            var end = Ext.getCmp(field.endDateField);
            end.setMinValue(date);
            end.validate();
            this.dateRangeMin = date;
          }
          /*
           * Always return true since we're only using this vtype to set the
           * min/max allowed values (these are tested for after the vtype test)
           */
          return true;
        },

        password : function(val, field) {
          if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
          }
          return true;
        },

        passwordText : 'Passwords do not match'
      });

      function logout(){
        Ext.Ajax.request({
          url : '/index/logout',
          success : function (result, request) {
            window.document.location.href = '/index/login';
          },
          failure : function (result, request){
            Ext.MessageBox.alert("提示","通讯失败，请从新操作");
          },
          method : 'GET'
        });
      }

      Ext.onReady(function() {

        var item1 = new Ext.Panel({
          title: 'Accordion Item 21',
          html: '&lt;empty panel&gt;11111',
          cls:'empty'
        });       

        var accordition = new Ext.Panel({
          region:'west',
          margins:'5 0 5 5',
          split:true,
          width: 210,
          layout:'accordion',
          //items: [item1]
          listeners: {
            beforerender: function() {
              //accordition.add(item1);
              Ext.Ajax.request({
                url : '/admin/getPersonPrivileges',
                success : function (result, response) {
                  //Ext.MessageBox.alert("提示","提交成功");
                  //alert(response[0].id);
                  var privileges = result.responseText;
                  privileges = Ext.util.JSON.decode(privileges);
                  privileges = privileges.root;
                  for (i=0;i<privileges.length;i++){
                    //alert(privileges[i].privilege_id);
                    accordition.add({
                      title: privileges[i].name,
                      html: '&lt;empty panel&gt;',
                      cls:'empty'
                    });
                    accordition.doLayout();
                  }
                },
                failure : function (result, response){
                },
                method : 'GET'
              });
            }
          }
        });

        
        //accordition.add(item1);
        //工作区
        var workTabs = new Ext.TabPanel({
          //renderTo:'tabs',
          region:'center',
          activeTab: 0,
          resizeTabs:true, // turn on tab resizing
          minTabWidth: 115,
          tabWidth:135,
          enableTabScroll:true,
          //width:600,
          //height:250,
          defaults: {autoScroll:true},
          plugins: new Ext.ux.TabCloseMenu()
        });

        var reminderPanel = new Ext.Panel({
          title: '系统提醒',
          id:'1',
          //html: '&lt;empty panel&gt;',
          //cls:'cellpadding:10',
          layout: {
            type:'vbox',
            align:'stretch'
          },
          defaults:{margins:'5 5 5 5'},
          //bodyStyle: 'padding:15px;align:center',
          listeners: {
            //expand: showAgileDiagram
          }//,
          //items:[warehouseSetupItem,warehouseSetupItem1,testMenuItem]
          //items:[tree]
          ,
          autoLoad: {
            url: "/test/tree",
            scripts: true
          }
        });
        workTabs.add(reminderPanel).show();
        
        var viewport = new Ext.Viewport({
          layout:'border',
          items:[accordition, workTabs]
        });
      });

    </script>
  </head>
  <body>
    <%= javascript_include_tag "/javascripts/application.js" %>
  </body>
</html>
